import request from '@/utils/request';
import type { User,Role } from '../entity';
import type { R } from '@/modules/common/entity'
import type { Token } from '@/modules/security/entity'
  
const API_URL = '/manager/user';
  
export class UserApi {
  // 获取所有用户
  async getAll(): Promise<R<User[]>> {
    return request({
      url: API_URL,
      method: 'get'
    })
  }
  
  // 获取单个用户  
  async getById(id: number): Promise<R<User>> {
    // 这里应该是实际的API调用，现在我们只返回一个模拟的用户数据
    return request({
      url: API_URL+"/"+id,
      method: 'get'
    })
  }  
  
  // 创建新用户  
  async create(user: User): Promise<R<User>> {
    return request({
      url: API_URL,
      method: 'post',
      data: user
    })
  }  
  
  // 更新用户  
  async update(id: number, user: User): Promise<R<User>> {
    return request({
      url: API_URL+"/"+id,
      method: 'put',
      data: user
    })
  }  
  
  // 删除用户  
  async delete(id: number): Promise<R<void>> {
    return request({
      url: API_URL+"/"+id,
      method: 'delete'
    })
  }
  // 获取用户的角色列表  
  async getRoles(id: number): Promise<R<Role>> {
    return request({
      url: API_URL+"/roles/"+id,
      method: 'get'
    })
  }

  // 添加登录方法
  async login(username: string, password: string): Promise<R<Token>> {
    return request({
      url: `${API_URL}/login`,
      method: 'post',
      data: { username, password }
    })
  }
}
